window.onload= function(){	
	requestDAU15Days();
	//console.log(screen.width);
}

function requestDAU15Days(){
	var optType = 13;
	var requestUrl=getDAUOptionUrl(optType);
	var processData= function(resultData){
		var flag=resultData.success;
		console.log("flag="+flag);
		if(flag==1){
			var data =resultData.data;
			console.log("length=" + data.length);
			var chartDataArray= new Array();
			var strContent="";
			for(var i=0;i<data.length;i++){
				var temp= data[i];				
				var time=temp.date;
				var charTime=time.slice(4,6)+'.'+time.slice(6,8);
				var time = time.slice(0,4)+'.'+charTime;					
				var daus=temp.DAU/10000;
				chartDataArray[i]=[charTime,daus];
				console.log("date=" + time+",dau="+daus);
				strContent+="<tr><td>"+time+"</td><td>"+daus+'w'+"</td></tr>";
				if(i==0){
					strTime1=time;
				}
				if(i==data.length-1){
					strTime2=time;
				}
			}
			strTime=strTime2+"-"+strTime1+" DAU";
			setTimetip(strTime);
			setContent(strContent);
			drawChart(chartDataArray);
		}
	}
	sendRequest(requestUrl,processData);
}

function setContent(strContent){
	var tbody= document.getElementById('table-body');
	tbody.innerHTML=strContent;
}

function setTimetip(strTime){
	var tTimetip=document.getElementById("timetip");
	tTimetip.innerHTML=strTime;
}

function drawChart(chartDataArray){
	for(var i=0;i<chartDataArray.length;i++){
		console.log(chartDataArray[i]);
	}	
	var myChart = new JSChart('chart', 'line');
	myChart.setDataArray(chartDataArray);
	myChart.setTitle('');
	myChart.setAxisNameX('');
	myChart.setAxisNameY('');
	myChart.setAxisPaddingTop(10);	
	myChart.setAxisPaddingLeft(30);
	myChart.resize(screen.width, 217);
	myChart.setGridColor('#5D5F5D');
	myChart.setGrid(true);
	//myChart.setBackgroundColor('#0000ff');	
	myChart.setShowXValues(false);
	myChart.draw();
}